<template>
    <div id="system" class="warp system">
        <postHead active="jianli" :showAction="true"></postHead>

        <div class="container">
            <div class="wrap_panel resumeimport">
                <div class="panel panel-default">
                    <div class="panel-heading">上传简历</div>
                    <div class="panel-body">

                     
                        <!-- /.resumeimport-tab -->

                        <!-- 新增简历 -->
                        <div class="resumeimport-info">
                            <div class="newresume">
                                <div class="resume">
                              

                               
                                    <biographicalNotesUpload></biographicalNotesUpload>
                                 

                                 
                                </div>
                                <!-- /.resume -->

                                <div class="newresume-edit">
                                    <div>
                                        <textarea id="pasteResume" class="form-control" style="height: 2680px;"  placeholder="将复制的简历内容粘贴在此处"></textarea>
                                    </div>
                                </div>
                            </div>
                            <!-- /.newresume -->

                            <!-- 保存按钮 -->
                            <div class="newresumebtn">
                                <input type="button" value="保存简历" class="btn btn-primary btn-lg jaysaveresume">
                            </div>
                        </div>

                    </div>
                    <!-- /.panel-body -->
                </div>
                <!-- /.panel -->
            </div>
            <!-- /.register -->
        </div>
    </div>
</template>
<script>
import {
    regionData,
    codeToText
} from "element-china-area-data";
import postHead from '@/components/postHead.vue';
import homeapi from '@/api/api.js'
import until from '@/api/until'
 import biographicalNotesUpload from '@/views/biographicalNotes/upload.vue'
export default {
    name: 'login',
    data() {
        return {
       
        }
    },
    components: {
        postHead,biographicalNotesUpload
    },
    mounted() {
        let title = this.$route.query.title
        if (title) {
            this.title = title
        }
        else {
            this.title = "AI爱招聘-上传简历"
        }
        this.getDictList();
        this.getIndustryList();
    },
    methods: {
        toLogin() {
            this.$router.push("/login/loginnew")
        },
        setActive(type) {
            this.active = type;
        },
        //获取数据字典
        async getDictList() {
            let data = await homeapi.getDictList();
            if (data.code == 200) {
                this.enterpriseScaleList = data.result.enterpriseScale
                this.enterpriseNatureList = data.result.enterpriseNature
                this.staffsNumList = data.result.staffsNum
            }
        },
        deleteImg() {
            this.form.licenceImg = ""
            this.form.licenceImgUrl = ""
        },

        //获取行业列表
        async getIndustryList() {
            let data = await homeapi.getIndustryList();
            if (data.code == 200) {
                data.result.map(res => {
                    res.text = res.name;
                    if (res.child.length > 0) {
                        res.child.map(json => {
                            json.text = json.name
                        })
                        res.children = res.child;
                        res.children.map(json => {
                            if (json.child.length > 0) {
                                json.child.map(item => {
                                    item.text = item.name
                                })
                                json.children = json.child

                            }
                            else {
                                json.children = [
                                    {
                                        text: json.text,
                                        id: json.id
                                    }
                                ]
                            }
                        })
                    }
                    else {
                        res.children = [
                            {
                                text: res.text,
                                children: [{
                                    text: res.text,
                                    id: res.id
                                }]
                            }
                        ]
                    }
                })

                this.enterpriseIndustry = data.result

            }
        },




        async sendCode() {
            let phone = this.phone
            if (phone.length != 11) {
                this.$message.error("请传入正确的手机号")
                return false;
            }

            let data = await homeapi.sendCode({ phone });

            if (data.code == 200) {
                this.showCode = false
                this.getTimeNext();
            }
            else {
                this.$message.error(data.message)

            }
        },

        getTimeNext() {
            if (this.time > 0) {
                this.time = this.time - 1;
                setTimeout(() => {
                    this.getTimeNext();
                }, 1000)
            }
            else {
                this.showCode = true;
                this.time = 60
            }
        },
        setCheck() {
            this.haveCheck = true;
        },
        async toRegister() {
            if (this.active == 2) {
                let code = this.code
                let phone = this.phone

                let type = this.active
                let form = this.userForm;
                form.code = code;
                form.phone = phone
                this.loading = true;
                let data = await homeapi.registerUser(form);
                if (data.code == 200) {
                    this.$message.success("注册成功")
                    until.setCookie("token", data.result);
                    this.$router.push("/user")


                }
                else {
                    this.loading = false
                    this.$message.error(data.message)
                }
            }
            else {
                let code = this.code
                let phone = this.phone
                let type = this.active
                let form = this.form;
                form.code = code;
                form.phone = phone
                this.loading = true;
                let data = await homeapi.registerCompany(form);
                if (data.code == 200) {
                    this.$message.success("注册成功")
                    until.setCookie("token", data.result);
                    this.$router.push("/")



                }
                else {
                    this.loading = false
                    this.$message.error(data.message)
                }
            }

        },
        async getUserInfo() {
            let data = await homeapi.getUserinfo();
            if (data.code == 402) {

            }
            if (data.code == 403) {
                this.$router.push("/company")

            }
            if (data.code == 200) {

            }

        },

        async sureEdit() {
            if (this.active == 1) {
                let form = this.form;

                let data = await homeapi.editCompany(form);
                if (data.code == 200) {
                    this.loading = false
                    this.$message.success("注册成功")
                    this.$router.push("/")
                }
            }
            else {
                let form = this.form;

                let data = await homeapi.editUser(form);
                if (data.code == 200) {
                    this.loading = false
                    this.$message.success("注册成功")
                    this.$router.push("/")
                }
            }

        },
        async changeFile(e) {
            if (e.target.files.length > 0) {
                let file = e.target.files[0]
                var formData = new FormData();
                // 服务端要求参数是 pic1 
                formData.append('file', file);
                let data = await homeapi.uploadFile(formData);
                if (data.code == 200) {

                    this.form.licenceImgUrl = data.result.url
                    this.form.licenceImg = data.result.path
                }
            }

        }


    }
}

</script>

<style scoped lang="less">
.footer {
    position: fixed;
}

.container {
    width: 100%;
    height: calc(100vh - 125px);
    overflow: auto;
    margin-top: 15px;
}

.main-left {
    position: fixed;
    top: 95px;
    bottom: 30px;
    background: #fff;
}

.system-lt {
    border: 0px;
}

.system-rt {
    border: 0px;
}

.main-right {
    margin-left: 0px;
}

.navbar-header {
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
}

.navbar-header span {
    font-size: 24px;
    color: #FC7B24;
    font-weight: bold;
}

.upload_div {
    width: 80px;
    height: 80px;
    border: 1px solid #e6e6e6;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    cursor: pointer;
}

.upload_div input {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    opacity: 0;
    cursor: pointer;
}

.upload_div i {
    font-size: 18px;
}

.register-form-control {
    display: flex;
    align-items: center;
    justify-content: flex-start;
}
</style>
